﻿function public_getCookie(name){
	var str = document.cookie;
	if(!str || str.indexOf(name + "=") < 0) // 寻找name=  
                return;  
            var cookies = str.split("; ");      // 用;将所有的Cookie分隔开  
            for(var i=0; i<cookies.length; i++){    // 遍历每个Cookie  
                var cookie = cookies[i];        // 当前Cookie  
                if(cookie.indexOf(name + "=") == 0){    // 如果名字为name  
                    var value = cookie.substring(name.length + 1);  
                                                // 获取value  
                    return decodeURI(value);    // 将value解码，并返回  
                }  
            }  
}

function public_setCookie(name, value){

	var cookieString = name + "=" + escape(value);

  	var date=new Date();
  	date.setTime(date.getTime() + 100*24*3600*1000);  
  	cookieString += "; expires=" + date.toGMTString();
	
  	document.cookie = cookieString;
}

//改变背静图片
function public_changeBG(index){
	//alert(index);
	var path = eval("bgpath" + index);
	eval("$('body').css('background-image', 'url("+path+")');");
}

function public_getIdFromString(str) {
	return str.substring(str.indexOf("_") + 1);
}
//2010-11-18 15:44:55

function public_getCurrentDateTime(){
	var str = "";
	var now = new Date();
	
	str += now.getFullYear() + "-";
	str += now.getMonth()+1 + "-";
	str += now.getDate() + " ";

	var h = now.getHours().toString();
	var m = now.getMinutes().toString();
	var s = now.getSeconds().toString();

	str += (h.length <2 ? "0"+h:h) + ":";
	str += (m.length <2 ? "0"+m:m) + ":";
	str += s.length <2 ? "0"+s:s;
	return str;

}

//&nbsp;
//&lt;
//&gt;

//转义符 ---> HTML
function transferToHTML(str){
	var transferchars = new Array("&nbsp;", "&lt;", "&gt;", "&amp;", "&quot;", "&#039;");
	var htmls = new Array(" ", "<", ">", "&", "\"", "'");
	
	for(var i=0; i<transferchars.length; i++){
		var c = transferchars[i];
		var h = htmls[i];
		while(str.indexOf(c) >= 0)
			str = str.replace(c, h);
	}
	return str;
}

function getUserFromArray(userid){
	var u = null;
	$(myfriendgroups).each(function(i, v){

		if(i != myfriendgroups_index){//不遍历最后一组（黑名单）
			$(myfriendgroups[i]).each(function(index, value){
				if(value.userid == userid)
					u = value;
			});
		}
	});
	return u;
}

